package com.woniu.user.mapper;

import com.woniu.user.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.user.vo.UserLoginVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author hushunlai
 * @since 2023-05-22
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select id, mobile, password, avatar, name, gender, user_type, vip, is_deleted, openid, comment_status, bitcoin, create_time, store_id from t_user where mobile=#{mobile}")
    User getByMobile(String mobile);

    @Update("update t_user set bitcoin = bitcoin - #{amount} where mobile = #{mobile}")
    void updateAmount(@Param("mobile") String mobile, @Param("amount") BigDecimal amount);

    @Update("update t_user set bitcoin = bitcoin + #{amount} where mobile = #{mobile}")
    void addAmount(@Param("mobile") String mobile, @Param("amount") BigDecimal amount);

    @Update("update t_user set store_id = #{storeId} where mobile = #{mobile}")
    void updateStoreId(@Param("mobile") String mobile, @Param("storeId") Integer storeId);
}
